<template>
  <div class="mod-sp__spmatchitemteam">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.matchName" placeholder="赛事" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.item" placeholder="赛项" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.groupName" placeholder="队伍名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="matchName" label="赛事" header-align="center" align="center"></el-table-column>
      <el-table-column prop="itemName" width="180" label="赛项" header-align="center" align="center"></el-table-column>
      <el-table-column prop="groupName" width="180" label="组别" header-align="center" align="center"></el-table-column>
      <el-table-column prop="groupNum" label="参赛队伍数" header-align="center" align="center"></el-table-column>
      <el-table-column prop="userNum" label="参赛人数" header-align="center" align="center"></el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="230">
        <template v-slot="scope">
          <el-button type="text" size="small" @click="detailHandle(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, reactive, toRefs } from "vue";
import AddOrUpdate from "./spmatchitemteam-add-or-update.vue";
import baseService from "@/service/baseService";

export default defineComponent({
  components: {
    AddOrUpdate
  },
  setup() {
    const state = reactive({
      getDataListURL: "/sp/spmatchitemteam/groupCount",
      getDataListIsPage: true,
      exportURL: "/sp/spmatchitemteam/export",
      deleteURL: "/sp/spmatchitemteam",
      deleteIsBatch: true,
      dataForm: {
        id: "",
        itemType: "",
        matchName: "",
        item: "",
        matchItemId: "",
        teamId: "",
        groupName: "",
        isRise: "",
        status: "",
        type: "pass"
      }
    });
    return { ...useView(state), ...toRefs(state) };
  },
  watch: {},
  mounted() {
    //获取上个页面传来的参数
    //id赛项id
    this.dataForm.id = this.$route.query.id + "";
    this.dataForm.itemType = this.$route.query.itemType + "";
    this.query();
    //console.log('=====================',id);
  },
  methods: {
    detailHandle(row: any) {
      this.$router.push({
        path: "/sp/spmatchitemrecord5",
        query: {
          id: row.id,
          groupName: row.groupName,
          matchItemId: this.dataForm.id,
          itemType: this.dataForm.itemType,
          drawOpen: row.drawOpen,
          isDraw: row.isDraw
        }
      });
    },
    endDrawHandle(groupId?: string) {
      this.$confirm("确认结束抽签？", this.$t("prompt.title"), {
        confirmButtonText: this.$t("confirm"),
        cancelButtonText: this.$t("cancel"),
        type: "warning"
      }).then(() => {
        baseService.get("/sp/spmatchitemteam/endDraw", { id: this.dataForm.id, groupId: groupId }).then((res) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          } else {
            this.query();
          }
        });
      });
    },
    reDrawHandle(groupId?: string) {
      this.$confirm("确认重新抽签？", this.$t("prompt.title"), {
        confirmButtonText: this.$t("confirm"),
        cancelButtonText: this.$t("cancel"),
        type: "warning"
      }).then(() => {
        baseService.get("/sp/spmatchitemteam/reDraw", { id: this.dataForm.id, groupId: groupId }).then((res) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          } else {
            this.query();
          }
        });
      });
    }
  }
});
</script>
